package cn.itcast.activiti.servlet.processinstance;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;

import cn.itcast.activiti.common.ProcessEngineUtils;

/**
 * 根据流程定义的id启动流程实例
 * @author LEE.SIU.WAH
 * @email lixiaohua7@163.com
 * @date 2016年5月6日 下午2:43:15
 * @version 1.0
 */
@WebServlet("/startProcessInstanceById.action")
public class StartProcessInstanceByIdServlet extends HttpServlet{

	private static final long serialVersionUID = -939504674385158318L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String pdId=request.getParameter("pdId");
		
		
		
		/** 获取流程引擎 */
		ProcessEngine pe=ProcessEngineUtils.getProcessEngine();
		/** 获取运行时服务 */
		RuntimeService rs=pe.getRuntimeService();
		
		//定义流程变量
		Map<String,Object> params=new HashMap<String,Object>();
		List<String> list=new ArrayList<String>();
		list.add("test1");
		list.add("test2");
		list.add("test3");
		list.add("test4");
		list.add("test5");
		
		params.put("userLists", list);
		
		/** 根据流程定义的id启动流程实例 */
		ProcessInstance pi=rs.startProcessInstanceById(pdId,params);
	
		
		response.sendRedirect(request.getContextPath()+"/queryProcessDefinition.action");
	}
	
	

}
